package com.byxm.wlgw.control.admin;

import java.util.List;
import java.util.Map;



import com.byxm.wlgw.bean.Yhxx_glBean;
import com.byxm.wlgw.common.ComConst;
import com.byxm.wlgw.common.ComUtil;
import com.byxm.wlgw.control.BaseAction;
import com.byxm.wlgw.service.Yhxx_glService;
import com.opensymphony.xwork2.ActionContext;
/**
 * 后台管理用户信息Action
 * @author Administrator
 *
 */
public class Yhxx_glAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	
	private List<Yhxx_glBean> lstyhxxgl;
	
	private Yhxx_glBean yhxxglBean;
	
	private Yhxx_glBean yhxxglBean2;//用于添加修改
	
	private String yhxxglid="";
	
	private boolean bflag;
	
	Map<String,Object> session;
	
	private String searchString="";
	
	/******service**********/
	Yhxx_glService yhxx_glservice=new Yhxx_glService();

	/**
	 * 登陆
	 * @return
	 */
	public String login(){
		if(yhxxglBean==null){
			yhxxglBean=new Yhxx_glBean();
		}
		session = ActionContext.getContext().getSession();
		String resultStr="";
		//如果session里有该对象就返回admin/index.jsp
		if(session.get(ComConst.YHXX_GL_SESSION)!=null){
			resultStr="success_01";
		}
		//如果session为空跳转到,且用户名信息为空 则跳转到登陆页面
		if(session.get(ComConst.YHXX_GL_SESSION)==null&&yhxxglBean.getYhxxglzh().trim()==""){
			resultStr="input";
		}
		//如果session为空，且用户名信息不为空
		if(session.get(ComConst.YHXX_GL_SESSION)==null&&!ComUtil.isNull(yhxxglBean.getYhxxglzh())){
			//去数据库匹配
			if(!ComUtil.isNull(yhxx_glservice.findYhxxgl(yhxxglBean).getYhxxglzh())){
				session.put(ComConst.YHXX_GL_SESSION, yhxxglBean);
				resultStr="success_01";
			}else{
				resultStr="input";
			}
			
		}
		return resultStr;
	}
	
	/**
	 * 登出
	 * @return
	 */
	public String exit(){
		session = ActionContext.getContext().getSession();
		if(session.get(ComConst.YHXX_GL_SESSION)!=null){
			session.remove(ComConst.YHXX_GL_SESSION);
		}
		return "success_02";
	}
	/**
	 * 加载单个用户信息
	 * @return
	 */
	public String load(){
		if(yhxxglid.trim()!=""){
			yhxxglBean2=yhxx_glservice.findYhxxglBean(Integer.parseInt(yhxxglid));
		}
		if(yhxxglBean2==null){
			yhxxglBean2=new Yhxx_glBean();
		}
		return "success_03";
	}
	
	/**
	 * 保存
	 * @return
	 */
	public String save(){
		if(yhxxglBean2.getYhxxglid()==0){
			yhxx_glservice.saveYhxx_gl(yhxxglBean2);
		}else{
			try {
				yhxx_glservice.updateYhxx(yhxxglBean2);//修改用户信息
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "success_04";
	}
	
	/**
	 * 用户信息查看
	 * @return
	 */
	public String list(){
		lstyhxxgl=yhxx_glservice.findYhxxgllst(searchString);
		return "success_05";
	}
	
	/**
	 * 删除
	 * @return
	 */
	public String delete(){
		try {
			if(yhxx_glservice.deleteYhxx(Integer.parseInt(yhxxglid))){
				bflag=true;
			}else{
				bflag=false;
			}
		}  catch (Exception e) {
			e.printStackTrace();
		}
		return "del";
	}
	
	
	/********setter   getter******/
	

	public String getYhxxglid() {
		return yhxxglid;
	}
	public void setYhxxglid(String yhxxglid) {
		this.yhxxglid = yhxxglid;
	}

	public List<Yhxx_glBean> getLstyhxxgl() {
		return lstyhxxgl;
	}

	public void setLstyhxxgl(List<Yhxx_glBean> lstyhxxgl) {
		this.lstyhxxgl = lstyhxxgl;
	}

	public Yhxx_glBean getYhxxglBean() {
		return yhxxglBean;
	}

	public void setYhxxglBean(Yhxx_glBean yhxxglBean) {
		this.yhxxglBean = yhxxglBean;
	}

	public String getSearchString() {
		return searchString;
	}

	public void setSearchString(String searchString) {
		this.searchString = searchString;
	}

	public Yhxx_glBean getYhxxglBean2() {
		return yhxxglBean2;
	}

	public void setYhxxglBean2(Yhxx_glBean yhxxglBean2) {
		this.yhxxglBean2 = yhxxglBean2;
	}

	public boolean isBflag() {
		return bflag;
	}

	public void setBflag(boolean bflag) {
		this.bflag = bflag;
	}
	

}
